package MyArrayList;

public class List {

    static class Node {
        public int value;
        public Node next;

        public Node(int value, Node next) {
            this.value = value;
            this.next = next;
        }

    }

    public Node hand;

    public boolean contain(int k) {
        Node p = hand;
        while (p != null) {
            if (p.value == k) {
                return true;
            }
            p = p.next;
        }
        return false;

    }

    public int size() {
        Node p = hand;
        int size = 0;
        while (p != null) {
            size++;
            p = p.next;
        }
        return size;
    }

    //头插
    public boolean addFirst(int k) {
        Node p = hand;
        Node temp = p.next;
        p.next = new Node(k,temp);
        return true;
    }

    //尾插
    public boolean addLast(int k) {
        Node p = hand;
        while (p.next != null) {
            p = p.next;
        }
        p.next = new Node(k,null);
        return true;
    }
}
